package com.onefish.toolkit.cwe;

import org.apache.commons.exec.ExecuteException;
import org.apache.commons.exec.ExecuteResultHandler;

import java.io.ByteArrayOutputStream;

public class CustomResultHandler implements ExecuteResultHandler {

    private ByteArrayOutputStream outputStream;

    public CustomResultHandler(ByteArrayOutputStream outputStream) {
        this.outputStream = outputStream;
    }

    @Override
    public void onProcessComplete(int exitValue) {
        System.out.println("Command executed successfully with exit code: " + exitValue);
        System.out.println("Command output: " + outputStream.toString());
    }

    @Override
    public void onProcessFailed(ExecuteException e) {
        System.err.println("Command execution failed: " + e.getMessage());
    }
}
